<%-- 
    Document   : listForests
    Created on : 22.11.2013, 18:17:05
    Author     : Palo
--%>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="http://stripes.sourceforge.net/stripes.tld"%>
<%@ taglib prefix="f" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>


<f:message var="nadpis" key="top.showForest"/>

<s:layout-render name="/mainLayout.jsp" nadpis="${nadpis}">
    <s:layout-component name="body">
        <s:useActionBean beanclass="cz.muni.fi.pa165.mushroom.website.web.ForestActionBean" var="actionBean"/>
        <shiro:hasRole name="ROLE_USER">
            <s:form beanclass="cz.muni.fi.pa165.mushroom.website.web.ForestActionBean">
                <fieldset><legend><f:message key="showforest.new"/></legend>
                    <%@include file="/protected/forestForm.jsp"%>
                    <s:submit name="add"><f:message key="showforest.create"/></s:submit>
                    </fieldset>
            </s:form>
        </shiro:hasRole>
        <h2><f:message key="showForest.show"/></h2>
        <c:choose>
            <c:when test="${empty actionBean.forest}">
                <p><f:message key="forest.list.empty"/></p>
            </c:when>
            <c:otherwise>

                <table class="basic">
                    <tr>
                        <th><f:message key="showForest.name"/> </th>
                        <th><f:message key="showForest.description"/></th> 
                            <shiro:hasRole name="ROLE_USER">
                            <th></th>
                                <shiro:hasRole name="ROLE_ADMIN">
                                <th></th>
                                </shiro:hasRole>
                            </shiro:hasRole>
                    </tr>

                    <c:forEach items="${actionBean.forest}" var="forestDto">

                        <tr>
                            <td><c:out value="${forestDto.name}"/></td>
                            <td><c:out value="${forestDto.description}"/></td>
                            <shiro:hasRole name="ROLE_USER">
                                <td class="button"><s:link beanclass="cz.muni.fi.pa165.mushroom.website.web.ForestActionBean" event="edit">
                                        <s:param name="forestDto.id" value="${forestDto.id}"/>
                                        <f:message key="tab.edit"/>
                                    </s:link>
                                </td>

                                <shiro:hasRole name="ROLE_ADMIN">
                                    <td class="button"><s:link beanclass="cz.muni.fi.pa165.mushroom.website.web.ForestActionBean" event="delete">
                                            <s:param name="forestDto.id" value="${forestDto.id}"/>
                                            <f:message key="tab.delete"/>
                                        </s:link>
                                    </td>                                
                                </shiro:hasRole>
                            </shiro:hasRole>
                        </tr>

                    </c:forEach> 

                </table>
            </c:otherwise>
        </c:choose>
    </s:layout-component>
</s:layout-render>